home *** CD-ROM | disk | FTP | other *** search
/ Apple Reference & Presen…tion Library 2 (Reseller) / Apple R&P Lib Reseller v2.0.iso / 4-Fonts & Software / Demo Software / AppMaker / Demo AppMaker™ / Demo AppMaker™.rsrc / TmpC_204_MainMenu.txt < prev    next >
Encoding:
Text File  |  1989-04-09  |  3.7 KB  |  212 lines

  1. # (decoded with TMPL 13671)
  2. /* %filename% */
  3. /* Created %date% %time% by AppMaker */
  4.  
  5. %If MPW%
  6. #include <Types.h>
  7. #include <Quickdraw.h>
  8. #include <Controls.h>
  9. #include <Dialogs.h>
  10. #include <Events.h>
  11. #include <Lists.h>
  12. #include <Menus.h>
  13. #include <TextEdit.h>
  14.  
  15. %end if%
  16. #include "Globals.h"
  17. #include "ResourceDefs.h"
  18. %UsesFiles%
  19.  
  20. #include "%unitname%.h"
  21.  
  22. %If MPW%
  23. #include <Desk.h>
  24. #include <ToolUtils.h>
  25.  
  26. %end if%
  27. #define nil            0L
  28. %If MPW%
  29.  
  30. #pragma segment %unitname%
  31. %end if% 
  32.  
  33. /*----------*/
  34. void InitTitles ()
  35. {
  36.     %InitTitles%
  37. } /*InitTitles*/
  38.  
  39. /*----------*/
  40. void LoadMenus ()
  41. {
  42.     %GetMenus%
  43.  
  44.     %InsertMenus%
  45.  
  46.     DrawMenuBar ();
  47. } /*LoadMenus*/
  48.  
  49. /*----------*/
  50. void DoAbout (void);
  51. void DoAbout ()
  52. {
  53.     short            itemNr;
  54.     
  55.     itemNr = Alert (AboutID, nil);
  56. } /*DoAbout*/
  57.  
  58. /*----------*/
  59. void DoApple (short        itemNr);
  60. void DoApple (itemNr)
  61. short            itemNr;
  62. {
  63.     Str255            name;
  64.     short            refNum;
  65.  
  66.     switch (itemNr) {
  67.     case AppleAbout:
  68.             DoAbout ();
  69.         break;
  70.     default:
  71.             GetItem (AppleMenu, itemNr, name);
  72.             refNum = OpenDeskAcc (name);
  73.         break;
  74.     } /*switch*/
  75. } /*DoApple*/
  76.  
  77. /*----------*/
  78. void DoMenu (menuChoice)
  79. long            menuChoice;
  80. {
  81.     short            menuID;
  82.     short            itemNr;
  83.  
  84.     menuID = HiWord (menuChoice);
  85.     itemNr = LoWord (menuChoice);
  86.     
  87.     switch (menuID) {
  88.     case 0:
  89.             /*Do nothing*/;
  90.         break;
  91.     %HandleMenus%
  92.     } /*switch*/
  93.  
  94.     HiliteMenu (0);
  95. } /*DoMenu*/
  96.  
  97. /*----------*/
  98. MenuHandle        menu;
  99. Boolean            menuBarChanged;
  100.  
  101. /*----------*/
  102. void Enable (short        itemNr,
  103.              Boolean    enabled);
  104.  
  105. void Enable (itemNr, enabled)
  106. short        itemNr;
  107. Boolean        enabled;
  108. {
  109.     if (enabled) {
  110.         EnableItem  (menu, itemNr);
  111.     } else {
  112.         DisableItem (menu, itemNr);
  113.     }
  114. } /*Enable*/
  115.  
  116. /*----------*/
  117. void EnableTitle (MenuHandle    menu,
  118.                   Boolean        enabled);
  119. void EnableTitle (menu, enabled)
  120. MenuHandle        menu;
  121. Boolean            enabled;
  122. {
  123.     if (enabled != ((**menu).enableFlags & 1)) {
  124.         menuBarChanged = true;
  125.     }
  126.     if (enabled) {
  127.         EnableItem  (menu, 0);
  128.     } else {
  129.         DisableItem (menu, 0);
  130.     }
  131. } /*EnableTitle*/
  132.  
  133. /*----------*/
  134. void UpdateMenus ()
  135. {
  136.     WindowPeek        frontPeek;
  137.     Boolean            isFront;    /*is there a front window?*/
  138.     Boolean            isCur;        /*is there a current window?*/
  139.     Boolean            isDirty;    /*is it dirty?*/
  140.     Boolean            hasFile;    /*does it have a file?*/
  141.     Boolean            isSelected;    /*is anything selected?*/
  142.     Boolean            isDesk;        /*is the front window a desk acc?*/
  143.     Boolean            isText;        /*is there a current text field?*/
  144.     Boolean            isScrap;    /*is there any scrap?*/
  145.  
  146.     menuBarChanged = false;
  147.  
  148.     isFront        = (FrontWindow () != nil);
  149.     isCur        = (curWindow != nil);
  150.     isDirty     = false;
  151.     hasFile     = false;
  152.     isSelected    = false;
  153.     if (isCur) {
  154.         isDirty        =  cur->dirty;
  155.         hasFile        = (cur->fileNum != 0);
  156.     }
  157.  
  158.     isDesk = false;
  159.     if (isFront) {
  160.         frontPeek    = (WindowPeek) FrontWindow ();
  161.         isDesk        = (frontPeek->windowKind < 0);
  162.     }
  163.     isText        = isCur && (cur->text != nil);
  164.     isScrap        = false;
  165.     if (isText) {
  166.         isSelected    = ((**(cur->text)).selStart != (**(cur->text)).selEnd);
  167.         isScrap        = (TEGetScrapLen () > 0);
  168.     }
  169.     
  170.     menu = FileMenu;
  171. %if defined FileClose%
  172.     Enable (FileClose,        isFront);
  173. %end if%
  174. %if defined FileSave%
  175.     Enable (FileSave,        isDirty);
  176. %end if%
  177. %if defined FileSaveAs%
  178.     Enable (FileSaveAs,        isDirty);
  179. %end if%
  180. %if defined FileRevert%
  181.     Enable (FileRevert,        isDirty && hasFile);
  182. %end if%
  183.     
  184.     menu = EditMenu;
  185.     if (isFront) {
  186. %if defined EditUndo%
  187.         Enable (EditUndo,        isDesk);
  188. %end if%
  189. %if defined EditCut%
  190.         Enable (EditCut,        isDesk || isSelected);
  191. %end if%
  192. %if defined EditCopy%
  193.         Enable (EditCopy,        isDesk || isSelected);
  194. %end if%
  195. %if defined EditPaste%
  196.         Enable (EditPaste,        isDesk || isScrap);
  197. %end if%
  198. %if defined EditClear%
  199.         Enable (EditClear,        isDesk || isSelected);
  200. %end if%
  201. %if defined EditSelectAll%
  202.         Enable (EditSelectAll,    isText);
  203. %end if%
  204.     }
  205.  
  206.     EnableTitle (EditMenu,     isFront);
  207.  
  208.     if (menuBarChanged) {
  209.         DrawMenuBar ();
  210.     }
  211. } /*UpdateMenus*/
  212.